#include"Engine.h"

namespace Advanced2D{
	Camera::Camera(){		
		setPosition(0, 600);
		setSizeView(800,600);			
	}

	void Camera::Init(Entity* entity){
		this->entity = entity;
	}

	void Camera::Update(){					
		float x = ((Sprite*)entity)->getPositionX() + (((Sprite*)entity)->getWidth() / 2) - (sizeView.x / 2);		
		
		if(x < 0){
			x = 0;
		}

		if( x > sizeWorld.x / 2){
			x = sizeWorld.x - sizeView.x;
		}

		setPositionX((int)x);		
	}
	
	D3DXVECTOR2 Camera::transform(D3DXVECTOR2& PositionWorldEntity){		
		D3DXMATRIX Transform;
		D3DXMATRIX FlipY;
		D3DXMATRIX Translate;
		D3DXVECTOR2 View;

		D3DXMatrixIdentity(&FlipY);
		FlipY._22 = -1;
		D3DXMatrixTranslation(&Translate, (float)-position.x , (float)position.y, 0);
		Transform = FlipY * Translate;
		D3DXVec2TransformCoord(&View, &PositionWorldEntity ,&Transform);

		return View;
	}
	
}